<template>
	<view class="login">
		<img src="../../static/login_logo.png" mode=""></img>
		<view class="loginInputWrap">
			<view class="loginTitle">手机号</view>
			<view class="codeWrap">
				<input class="input" type="text" v-model="phone" placeholder="请输入手机号" placeholder-class="pcs" />
			</view>
		</view>
		<view class="loginInputWrap">
			<view class="loginTitle">密码</view>
			<view class="codeWrap">
				<input class="input" type="password" v-model="password" placeholder="请输入密码" placeholder-class="pcs" />
			</view>
		</view>
		<button type="default" @click="handleLogin">立即登录</button>
		<image @click="dwxlogin" class="wechat" src="../../static/bg/wechat.png" mode=""></image>
		<view class="wechatMsg">点击微信图标自动登录</view>
	    <!-- <view class="register">还没有账号？<text @click="goRegister">立即注册</text></view> -->
	</view>
</template>

<script>
	import { dlogin,dwxlogin } from '@/request/api.js'; 
	export default {
		data() {
			return {
				phone: '',
				password: ''
			}
		},
		onLoad() {
			
		},
		methods: {
			// 登录
			handleLogin() {
				if(!/^1[3456789]\d{9}$/.test(this.phone)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: "none"
					})
					return
				}
				if(!this.password) {
					uni.showToast({
						title: '请输入密码',
						icon: "none"
					})
					return
				}
				let params = {
					// company_id:uni.getStorageSync('companyId'),
					openid:uni.getStorageSync('openid'),
					phone: this.phone,
					password: this.password
				}
				dlogin(params).then(res => {
					uni.setStorageSync('doctor',res.data)
					uni.setStorageSync('companyId',res.data.company_id)
					uni.setStorageSync('token',res.data.login_token)
					uni.setStorageSync('doctorToken',res.data.login_token)
					uni.setStorageSync('identity',2)
					uni.reLaunch({
						url:'/pages/my/my'
					})
				})
			},
			// 微信登录
			dwxlogin(){
				let params = {
					openid:uni.getStorageSync('openid')
				}
				dwxlogin(params).then(res => {
					uni.setStorageSync('doctor',res.data)
					uni.setStorageSync('companyId',res.data.company_id)
					uni.setStorageSync('token',res.data.login_token)
					uni.setStorageSync('doctorToken',res.data.login_token)
					uni.setStorageSync('identity',2)
					uni.reLaunch({
						url:'/pages/my/my'
					})
				})
			},
			// 去注册页
			goRegister() {
				uni.navigateTo({
					url: '../register/register'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		display: flex;
		flex-direction: column;
		align-items: center;

		img {
			width: 500upx;
			height: 500upx;
		}
		.loginInputWrap:last-of-type{
			margin-bottom: 80upx;
		}
		.loginInputWrap {
			width: 630upx;
			margin-bottom: 64upx;
			border-bottom: 1px solid #E5E5E5;

			.loginTitle {
				font-size: 28upx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #000000;
				margin-bottom: 16upx;
			}
			.codeWrap {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0upx 0px 16upx;
			}

			.input {
				// padding: 16upx 0px 32upx;
				font-size: 28upx;
			}

			.pcs {
				font-size: 28upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				line-height: 40px;
				color: #CCCCCC;
				opacity: 1;
			}
		}
		button{
			width: 630upx;
			height: 88upx;
			background: #F86C53;
			border-radius: 44upx;
			color: #FFFFFF;
			font-size: 36upx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			margin-bottom: 46upx;
		}
		button:after{
			border: none;
		}
		.register{
			font-size: 28upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #9F9F9F;
			text{
				color: #6996FE;
			}
		}
		.wechat{
			width: 120upx;
			height: 120upx;
			margin: 0 auto;
		}
		.wechatMsg{
			font-weight: bold;
			padding-top: 20upx;
			color: #68E1A8;
		}
	}
</style>
